﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text;
using AgileNYCWebService.Manager.Data;
using AgileNYCWebService.Manager.Data.Table;
using log4net.Config;
using log4net.Core;

namespace AgileNYCWebService
{
	// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "AgileSchedules" in code, svc and config file together.
	// NOTE: In order to launch WCF Test Client for testing this service, please select AgileSchedules.svc or AgileSchedules.svc.cs at the Solution Explorer and start debugging.

	[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
	public class AgileEvents : IAgileEvents
	{
		public string Events(string userToken, int offset, int limit)
		{
			Logger.Log.Info("get events");
			if (limit > 100)
				limit = 100;

			JsonResult result = new DataManager(userToken).GetEvents(offset, limit, offset < 0);
			if (string.IsNullOrEmpty(result.Error))
			{
				return result.Result;
			}
			return result.Error;
		}

		public string CheckIn(string userToken, int eventId, bool isCheckIn)
		{
			JsonResult result = new DataManager(userToken).CheckIn(eventId, isCheckIn);
			if (string.IsNullOrEmpty(result.Error))
			{
				return result.Result;
			}
			return result.Error;
		}

		public string Rating(string userToken, int eventId, float ratingValue)
		{
			JsonResult result = new DataManager(userToken).Rating(eventId, ratingValue);
			if (string.IsNullOrEmpty(result.Error))
			{
				return result.Result;
			}
			return result.Error;

		}

		public string Event(string userToken, int eventId)
		{
			JsonResult result = new DataManager(userToken).GetEvent(eventId);
			if (string.IsNullOrEmpty(result.Error))
			{
				return result.Result;
			}
			return result.Error;
		}
	}
}
